<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
	<title>Real Time Syntax Highlighting Code Editor JavaScript</title>
	<link type="text/css" rel="stylesheet" href="rtsh-java.css" />
	<script type="text/javascript" src="rtsh.js"></script>
	<script type="text/javascript">
	RTSH.language = 'java';
	</script>
</head>

<!-- no line break between body and pre -->
<body id="ffedt"><pre id="ieedt">import java.io.FileFilter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

// TODO: fix login var

/**
 * Project ECCO - File manager class
 * 
 * @author Fernando M.A.d.S.
 *
 */
public class FileManager extends HttpServlet {

	private static final long serialVersionUID = 1L;
	private static String login = "feanndor"; // session var should come here
	private static String usersPath = System.getProperty("user.dir")+File.separator+"htdocs"+File.separator+"ecco"+File.separator+"users"+File.separator;
	private static File dir = new File(usersPath+login+File.separator);
	static boolean existDirectories = false;
	static int isDirectory = 0;

	public FileFilter filterFiles(File dir) {
		return (new FileFilter() {
			public boolean accept(File pathname) {
				return !(pathname.isDirectory());
			}
		});
	}

	public void listProjects(File dir, PrintWriter out) {
		try{
			File[] dirs = dir.listFiles();
			for (int i = 0; i &lt; dirs.length; i++) {
				if (dirs[i].isDirectory()) {
					out.write("&lt;project name="+dirs[i].getName()+"&gt;");
				} else {
					continue;
				}
				listDir(dirs[i],out);
				out.write("&lt;/project&gt;");
			}
			File[] files = dir.listFiles(filterFiles(dir));
			for (int i = 0; i &lt; files.length; i++) {
				System.out.println(files[i].getName());
			}
		}catch(Exception e){
			out.println("&lt;info&gt;error&lt;/info&gt;");
			return;
		}
	}
}
</pre>
</body>
</html>
